//
//  MHTopicMoreBookHeaderView.m
//  ManHua
//
//  Created by lanou on 15/10/28.
//  Copyright © 2015年 蓝欧科技. All rights reserved.
//

#import "MHTopicMoreBookHeaderView.h"
@interface MHTopicMoreBookHeaderView()<UIWebViewDelegate>
@end

@implementation MHTopicMoreBookHeaderView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(instancetype)initWithFrame:(CGRect)frame
{self=[super initWithFrame:frame];
    if (self) {
        _descriptionWebView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, Width, 10)];
        _descriptionWebView.delegate=self;
        [self addSubview:_descriptionWebView];
        self.readButtton=[UIButton  buttonWithType:UIButtonTypeSystem];
        self.readButtton.frame=CGRectMake(10, CGRectGetMaxY(_descriptionWebView.frame), 30, 30);
        [self.readButtton setTitle:@"☆" forState:UIControlStateNormal];
        [self.readButtton setTitleColor:KThemPinkColor forState:UIControlStateNormal];
        [self addSubview:_readButtton];
        _readLabel=[[UILabel alloc]initWithFrame:CGRectMake(40, CGRectGetMaxY(_descriptionWebView.frame),Width/3, 30)];
        _readLabel.text=@"阅读列表";
        _readLabel.textColor=KThemPinkColor;
        _readLabel.font=[UIFont systemFontOfSize:12];
        [self addSubview:_readLabel];
        
    }
    return self;
}
-(void)setWeburl:(NSString *)weburl
{
    _weburl =weburl;
    [_descriptionWebView loadHTMLString:weburl baseURL:nil];
    
}
//当web加载完毕之后计算webView的高度
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    CGFloat webheight=[[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"]floatValue];
    _descriptionWebView.frame=CGRectMake(0, 0, Width, webheight);
    _readButtton.frame=CGRectMake(10, CGRectGetMaxY(_descriptionWebView.frame), 30, 30);
    _readLabel.frame=CGRectMake(40, CGRectGetMaxY(_descriptionWebView.frame), Width/3, 30);
    CGFloat hight=CGRectGetMaxY(_readLabel.frame);
    if (self.changeHeaderSectionFrameBlock!=nil) {
        self.changeHeaderSectionFrameBlock(hight);
    }
    
}
@end
